package com.cgx.tablet.beeper.presenter;

import android.content.Context;

import com.cgx.tablet.beeper.R;
import com.cgx.tablet.beeper.api.ApiCallback;
import com.cgx.tablet.beeper.api.ApiUtil;
import com.cgx.tablet.beeper.base.BasePresenter;
import com.cgx.tablet.beeper.bean.BizWaitBean;
import com.cgx.tablet.beeper.bean.CallBean;
import com.cgx.tablet.beeper.bean.response.InfoResponse;
import com.cgx.tablet.beeper.bean.response.ListResponse;
import com.cgx.tablet.beeper.bean.response.MsgResponse;
import com.cgx.tablet.beeper.utils.SharedPreferenceUtil;
import com.cgx.tablet.beeper.view.IBusinessView;

/**
 * 业务操作
 */
public class BusinessPresenter extends BasePresenter {

    private IBusinessView view;

    public BusinessPresenter(IBusinessView view) {
        super(view);
        this.view = view;
    }

    //拨号
    public void call() {
        callApi(ApiUtil.apiService.call(), new ApiCallback<InfoResponse<CallBean>>() {
            @Override
            public void onSuccess(final InfoResponse<CallBean> callBeanInfoResponse) {
                view.onCallSuccess(callBeanInfoResponse.getInfo());
            }

            @Override
            public void onFail(String code, String msg) {
                view.onCallFail(code, msg);
            }
        });
    }

    //追呼
    public void recall(String tid) {
        callApi(ApiUtil.apiService.recall(tid), new ApiCallback<MsgResponse>() {
            @Override
            public void onSuccess(final MsgResponse msgResponse) {
                view.onRecallSuccess();
            }

            @Override
            public void onFail(String code, String msg) {
                view.onRecallFail(code, msg);
            }
        });
    }

    //开始处理
    public void deal(String tid) {
        callApi(ApiUtil.apiService.deal(tid), new ApiCallback<MsgResponse>() {
            @Override
            public void onSuccess(final MsgResponse msgResponse) {
                view.onDealSuccess();
            }

            @Override
            public void onFail(String code, String msg) {
                view.onDealFail(code, msg);
            }
        });
    }

    //完成
    public void finish(String tid) {
        callApi(ApiUtil.apiService.finish(tid), new ApiCallback<MsgResponse>() {
            @Override
            public void onSuccess(final MsgResponse msgResponse) {
                view.onFinishSuccess();
            }

            @Override
            public void onFail(String code, String msg) {
                view.onFinishFail(code, msg);
            }
        });
    }

    //弃号
    public void abandon(String tid) {
        callApi(ApiUtil.apiService.abandon(tid), new ApiCallback<MsgResponse>() {
            @Override
            public void onSuccess(final MsgResponse msgResponse) {
                view.onAbandonSuccess();
            }

            @Override
            public void onFail(String code, String msg) {
                view.onAbandonFail(code, msg);
            }
        });
    }

    //获取业务等候信息
    public void refreshBiz() {
        if (ApiUtil.apiService == null)
            ApiUtil.init(((Context) view).getString(R.string.service_domain, SharedPreferenceUtil.getIP((Context) view), SharedPreferenceUtil.getPort((Context) view)));
        callApi(ApiUtil.apiService.refreshBiz(), new ApiCallback<ListResponse<BizWaitBean>>() {
            @Override
            public void onSuccess(final ListResponse<BizWaitBean> response) {
                view.onRefreshBizSuccess(response.getData());
            }

            @Override
            public void onFail(String code, String msg) {
                view.onRefreshBizFail(code, msg);
            }
        }, false);
    }

    //帮助
    public void help() {
        callApi(ApiUtil.apiService.help(), new ApiCallback<MsgResponse>() {
            @Override
            public void onSuccess(final MsgResponse response) {
                view.onHelpSuccess();
            }

            @Override
            public void onFail(String code, String msg) {
                view.onHelpFail(code, msg);
            }
        });
    }
}
